package demo1;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author liangzai
 * @Description:
 */
public class UserService {
    public static List<Socket> socketList = new ArrayList<>();

    public void start(){
        try {
            ServerSocket serverSocket = new ServerSocket(9999);
            System.out.println("服务器已启动！");
            UserName userName = new UserName();
            while(true) {
                Socket socket = serverSocket.accept();
                socketList.add(socket);
                System.out.println("有客服端连上了:" + userName.userName(socket.getInetAddress()));
                System.out.println("连接客服端数："+socketList.size());
                new Thread(new MessageThread(socket)).start();

            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
